package ph.edu.ics.sp.graphisched.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;

import org.jdesktop.application.Application;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
@SuppressWarnings("serial")
public class GraphiSchedIndexPanel extends javax.swing.JPanel {
	private JFrame frame;
	private JLabel heading;
	private JLabel selectTaskLabel;
	private JButton nextButton;
	private JRadioButton openExisting;
	private JRadioButton createNew;
	private ButtonGroup newOrOld;

	public GraphiSchedIndexPanel(JFrame frame) {
		super();
		this.frame = frame;
		initGUI();
	}

	private void initGUI() {
		try {
			this.setPreferredSize(new java.awt.Dimension(352, 222));
			this.setLayout(null);
			{
				heading = new JLabel();
				this.add(heading);
				heading.setName("heading");
				heading.setBounds(59, 14, 226, 42);
			}
			{
				selectTaskLabel = new JLabel();
				this.add(selectTaskLabel);
				selectTaskLabel.setBounds(21, 90, 260, 14);
				selectTaskLabel.setName("selectTaskLabel");
			}
			{
				createNew = new JRadioButton();
				this.add(createNew);
				createNew.setBounds(49, 121, 128, 18);
				createNew.setName("createNew");
				getNewOrOld().add(createNew);
				createNew.setSelected(true);
			}
			{
				openExisting = new JRadioButton();
				this.add(openExisting);
				openExisting.setBounds(201, 121, 128, 18);
				openExisting.setName("openExisting");
				getNewOrOld().add(openExisting);
			}
			{
				nextButton = new JButton();
				this.add(nextButton);
				nextButton.setBounds(125, 168, 96, 32);
				nextButton.setName("nextButton");
				nextButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						nextButtonActionPerformed(evt);
					}
				});
			}

			Application.getInstance().getContext().getResourceMap(getClass())
					.injectComponents(this);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private ButtonGroup getNewOrOld() {
		if (newOrOld == null) {
			newOrOld = new ButtonGroup();
		}
		return newOrOld;
	}

	private void nextButtonActionPerformed(ActionEvent evt) {
		if (createNew.isSelected()) {
			frame.setContentPane(new CreateNewFilePanel(frame, true));
			frame.setVisible(true);
			frame.setResizable(false);
			frame.pack();
			frame.setLocationRelativeTo(null);
			frame.repaint();
		} else {
			frame.setContentPane(new OpenExistingFilePanel(frame));
			frame.setVisible(true);
			frame.setResizable(false);
			frame.pack();
			frame.setLocationRelativeTo(null);
			frame.repaint();
		}
	}

}
